module.exports = app => {		//app参数（server/index.js传入app参数）
	const router = require('express').Router()	//引入router模块
	const mongoose = require('mongoose')	//引入mongoose
	// const Article = require('../../models/Article')
	//	引入模型（模型已被创建）
	const Category = mongoose.model('Category')
	const Article = mongoose.model('Article')
	const Hero = mongoose.model('Hero')

	/*
	**	@routes http://localhost:3000/web/api/news/init
	**	新闻导入接口（修改数据即可）
	*/
	router.get('/news/init',async(req, res)=>{
		// Mongoose学习笔记：https://blog.csdn.net/u011500781/article/details/72783450
		const parent = await Category.findOne({ name: '新闻分类'})//找到'新闻分类'（作为parent）
		const cats = await Category.find().where({ parent : parent }).lean()//找出parent属性为parent（新闻分类下的对象），然后lean展开数据
		// console.log(cats) 看下面
		const newsTitles =  ["10月19日全服不停机更新公告", "张良-黄金白羊座登场 参与活动抽永久英雄", "张良AR相机使用异常说明公告", "黄金白羊座语音彩蛋触发异常说明", "11月18日违规广告专项惩罚公告", "圣斗士联动！信物熔铸赢【圣斗士系列皮肤】", "张靓颖西施英雄主打歌翻唱大赛，参与活动打榜赢靓颖签名照！", "天后张靓颖倾情献唱，王者荣耀西施主打歌《幻纱之灵》正式上线", "西施主打歌《幻纱之灵》即将上线，张靓颖携手KPL明星轰炸斗鱼直播间", "新晋越剧女小生，王者荣耀·上官婉儿全息首演！", "10月19日全服不停机更新公告", "张良AR相机使用异常说明公告", "黄金白羊座语音彩蛋触发异常说明", "10月18日违规广告专项惩罚公告", "净化游戏环境声明及处罚公告（10月10日-11月17日）", "张良-黄金白羊座登场 参与活动抽永久英雄", "KPL季后赛开赛 参与活动送好礼", "【翻牌达人】抢SNK机器人", "告别孤单 浪漫峡谷陪你狂欢 秒杀皮肤限时返场", "感恩有你 李白新星元登场 峡谷全新福利来袭", "王者少年来袭！区域联赛开幕式集锦，你想看的都在这里！", "竞猜王者荣耀城市赛总决赛冠军，“城市探秘”Q币奖励加码", "重新定义配音新玩法 原创内容大赛配音比赛再次来袭", "高校赛区域联赛线下赛周末打响，王者少年的英雄梦时刻！", "王者荣耀高校联赛海选赛步入第四周，峡谷追梦就是此刻"]	
		//新闻标题（chrome devtool -> console   $$('.news_title .title').map(el => el.innerHTML)）
		const newsList = newsTitles.map(title => {
			const randomcats = cats.slice(0).sort((a,b) => Math.random() - 0.5)
			return {
				categories:randomcats.slice(0,2), //slice(0,2)返回以索引0,1为值的数组（比如新闻公告，新闻活动等）
				title: title
			}
		})
		await Article.deleteMany({})	//清空管理后台稳重列表的数据
		await Article.insertMany(newsList)	//将newsLList插入到Article模型中（categories，title）
		res.send(newsList)
	})
	

	
	/*
	** 	@routes http://localhost:3000/web/api/news/List
	**	新闻列表
	*/
	router.get('/news/list', async (req, res) => {
    // const parent = await Category.findOne({
    //   name: '新闻分类'
    // }).populate({
    //   path: 'children',
    //   populate: {
    //     path: 'newsList'
    //   }
		// }).lean()
		// 以上方法不太行，每一个分类要有5篇文章
    const parent = await Category.findOne({
      name: '新闻分类'//找到新闻分类作为父分类
    })
    const cats = await Category.aggregate([	//聚合查询，一次执行几次查询的工作量，得到想要的结果
      { $match: { parent: parent._id } },	//条件查询（类似where），匹配父分类的id
      {
        $lookup: {		//关系数据库的join，以新闻为主题，查其他集合
          from: 'articles',	//关联哪个表/集合，模型名的小写复数形式，具体看mongoose.model
          localField: '_id',	//本地键	
          foreignField: 'categories',	//外地键，文章的
          as: 'newsList'	//名字
        }
      },
      {
        $addFields: {		//修改字段
          newsList: { $slice: ['$newsList', 5] }	//slice ,取newsList中的5个元素
        }
      }
		])
    const subCats = cats.map(v => v._id)		//遍历出cats(数组)中的id
    cats.unshift({	//unshift 添加元素到数组的头部
      name: '热门',
      newsList: await Article.find().where({
        categories: { $in: subCats }			//categories: _id (插入)
      }).populate('categories').limit(5).lean()		//关联查询categories，限制5个，再展开数据
    })

    cats.map(cat => {														//一级遍历
      cat.newsList.map(news => {								//二级遍历
        news.categoryName = (cat.name === '热门')	//判断是否为热门
          ? news.categories[0].name : cat.name		//添加为热门（news.categoryName = news.categories[0].name），不然为其他（news.categoryName = cat.name）
        return news			//返回news
      })
      return cat			//返回cat
		})
		// console.log(cats)看下面
    res.send(cats)

  })



	/*
	** 	@routes http://localhost:3000/web/api/heroes/init
	**	导入英雄数据接口
	*/
	router.get('/heroes/init',async(req,res)=>{
		await Hero.deleteMany({})	//先删除英雄列表
		const rawData = [{"name":"热门","heroes":[{"name":"孙悟空","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/167/167.jpg"},{"name":"亚瑟","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/166/166.jpg"},{"name":"后羿","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/169/169.jpg"},{"name":"鲁班七号","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/112/112.jpg"},{"name":"铠","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/193/193.jpg"},{"name":"甄姬","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/127/127.jpg"},{"name":"孙尚香","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/111/111.jpg"},{"name":"安琪拉","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/142/142.jpg"},{"name":"妲己","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/109/109.jpg"},{"name":"吕布","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/123/123.jpg"}]},{"name":"战士","heroes":[{"name":"赵云","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/107/107.jpg"},{"name":"墨子","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/108/108.jpg"},{"name":"钟无艳","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/117/117.jpg"},{"name":"吕布","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/123/123.jpg"},{"name":"夏侯惇","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/126/126.jpg"},{"name":"曹操","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/128/128.jpg"},{"name":"典韦","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/129/129.jpg"},{"name":"宫本武藏","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/130/130.jpg"},{"name":"达摩","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/134/134.jpg"},{"name":"老夫子","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/139/139.jpg"},{"name":"关羽","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/140/140.jpg"},{"name":"程咬金","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/144/144.jpg"},{"name":"露娜","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/146/146.jpg"},{"name":"花木兰","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/154/154.jpg"},{"name":"橘右京","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/163/163.jpg"},{"name":"亚瑟","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/166/166.jpg"},{"name":"孙悟空","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/167/167.jpg"},{"name":"刘备","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/170/170.jpg"},{"name":"钟馗","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/175/175.jpg"},{"name":"杨戬","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/178/178.jpg"},{"name":"雅典娜","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/183/183.jpg"},{"name":"哪吒","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/180/180.jpg"},{"name":"铠","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/193/193.jpg"},{"name":"苏烈","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/194/194.jpg"},{"name":"裴擒虎","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/502/502.jpg"},{"name":"狂铁","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/503/503.jpg"},{"name":"孙策","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/510/510.jpg"},{"name":"李信","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/507/507.jpg"},{"name":"盘古","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/529/529.jpg"},{"name":"云中君","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/506/506.jpg"},{"name":"曜","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/522/522.jpg"},{"name":"马超","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/518/518.jpg"}]},{"name":"法师","heroes":[{"name":"小乔","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/106/106.jpg"},{"name":"墨子","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/108/108.jpg"},{"name":"妲己","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/109/109.jpg"},{"name":"嬴政","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/110/110.jpg"},{"name":"高渐离","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/115/115.jpg"},{"name":"孙膑","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/118/118.jpg"},{"name":"扁鹊","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/119/119.jpg"},{"name":"芈月","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/121/121.jpg"},{"name":"周瑜","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/124/124.jpg"},{"name":"甄姬","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/127/127.jpg"},{"name":"武则天","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/136/136.jpg"},{"name":"貂蝉","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/141/141.jpg"},{"name":"安琪拉","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/142/142.jpg"},{"name":"露娜","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/146/146.jpg"},{"name":"姜子牙","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/148/148.jpg"},{"name":"王昭君","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/152/152.jpg"},{"name":"张良","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/156/156.jpg"},{"name":"不知火舞","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/157/157.jpg"},{"name":"钟馗","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/175/175.jpg"},{"name":"诸葛亮","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/190/190.jpg"},{"name":"干将莫邪","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/182/182.jpg"},{"name":"女娲","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/179/179.jpg"},{"name":"杨玉环","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/176/176.jpg"},{"name":"弈星","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/197/197.jpg"},{"name":"米莱狄","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/504/504.jpg"},{"name":"司马懿","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/137/137.jpg"},{"name":"沈梦溪","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/312/312.jpg"},{"name":"上官婉儿","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/513/513.jpg"},{"name":"嫦娥","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/515/515.jpg"},{"name":"西施","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/523/523.jpg"}]},{"name":"坦克","heroes":[{"name":"廉颇","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/105/105.jpg"},{"name":"庄周","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/113/113.jpg"},{"name":"刘禅","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/114/114.jpg"},{"name":"钟无艳","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/117/117.jpg"},{"name":"白起","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/120/120.jpg"},{"name":"芈月","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/121/121.jpg"},{"name":"吕布","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/123/123.jpg"},{"name":"夏侯惇","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/126/126.jpg"},{"name":"达摩","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/134/134.jpg"},{"name":"项羽","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/135/135.jpg"},{"name":"程咬金","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/144/144.jpg"},{"name":"刘邦","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/149/149.jpg"},{"name":"亚瑟","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/166/166.jpg"},{"name":"牛魔","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/168/168.jpg"},{"name":"张飞","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/171/171.jpg"},{"name":"太乙真人","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/186/186.jpg"},{"name":"东皇太一","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/187/187.jpg"},{"name":"铠","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/193/193.jpg"},{"name":"苏烈","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/194/194.jpg"},{"name":"梦奇","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/198/198.jpg"},{"name":"孙策","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/510/510.jpg"},{"name":"嫦娥","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/515/515.jpg"},{"name":"猪八戒","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/511/511.jpg"}]},{"name":"刺客","heroes":[{"name":"赵云","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/107/107.jpg"},{"name":"阿轲","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/116/116.jpg"},{"name":"李白","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/131/131.jpg"},{"name":"貂蝉","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/141/141.jpg"},{"name":"韩信","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/150/150.jpg"},{"name":"兰陵王","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/153/153.jpg"},{"name":"花木兰","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/154/154.jpg"},{"name":"不知火舞","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/157/157.jpg"},{"name":"娜可露露","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/162/162.jpg"},{"name":"橘右京","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/163/163.jpg"},{"name":"孙悟空","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/167/167.jpg"},{"name":"百里守约","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/196/196.jpg"},{"name":"百里玄策","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/195/195.jpg"},{"name":"裴擒虎","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/502/502.jpg"},{"name":"元歌","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/125/125.jpg"},{"name":"司马懿","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/137/137.jpg"},{"name":"上官婉儿","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/513/513.jpg"},{"name":"云中君","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/506/506.jpg"},{"name":"马超","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/518/518.jpg"}]},{"name":"射手","heroes":[{"name":"孙尚香","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/111/111.jpg"},{"name":"鲁班七号","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/112/112.jpg"},{"name":"马可波罗","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/132/132.jpg"},{"name":"狄仁杰","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/133/133.jpg"},{"name":"后羿","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/169/169.jpg"},{"name":"李元芳","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/173/173.jpg"},{"name":"虞姬","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/174/174.jpg"},{"name":"成吉思汗","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/177/177.jpg"},{"name":"黄忠","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/192/192.jpg"},{"name":"百里守约","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/196/196.jpg"},{"name":"公孙离","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/199/199.jpg"},{"name":"伽罗","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/508/508.jpg"}]},{"name":"辅助","heroes":[{"name":"庄周","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/113/113.jpg"},{"name":"刘禅","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/114/114.jpg"},{"name":"孙膑","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/118/118.jpg"},{"name":"姜子牙","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/148/148.jpg"},{"name":"牛魔","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/168/168.jpg"},{"name":"张飞","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/171/171.jpg"},{"name":"蔡文姬","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/184/184.jpg"},{"name":"太乙真人","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/186/186.jpg"},{"name":"大乔","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/191/191.jpg"},{"name":"鬼谷子","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/189/189.jpg"},{"name":"明世隐","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/501/501.jpg"},{"name":"杨玉环","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/176/176.jpg"},{"name":"盾山","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/509/509.jpg"},{"name":"瑶","avatar":"https://game.gtimg.cn/images/yxzj/img201606/heroimg/505/505.jpg"}]}]
		for (let cat of rawData) {	//循环数组7个元素，cat为单个对象，用for of
			if (cat.name === '热门') {	//跳过热门
				continue	
			}
			// 找到当前分类在数据库中对应的数据
			const category = await Category.findOne({		//在category分类列表中找到战士等分类，然后将id值赋值到category，这是一个id值
        name: cat.name
			})
			cat.heroes = cat.heroes.map(hero => {				//遍历rawData中的heroes属性，进行操作后赋值给原来的cat.heroes
				hero.categories = [category]		//将category（id值，以数组["5dd4f10afd1311345155854b"],）赋值到hero.categories （新增categories属性）
				return hero											//返回hero（cat.heroes中的单个对象）
			})
			// console.log(cat.heroes) 看下面
			// 录入英雄
			await Hero.insertMany(cat.heroes)	//再录入英雄列表，上面添加的categories不会显示出来，，但是图片啥的都录进去了
		}
		res.send(await Hero.find())		//发送给客户端
	})



	/*
	** 	@routes http://localhost:3000/web/api/heroes/list
	**	英雄列表接口
	*/
	router.get('/heroes/list',async(req,res)=>{
		const parent = await Category.findOne({		//Category中找到父级分类（英雄分类）的_id，赋值给parent
      name: '英雄分类'	// console.log(parent)   //{_id: "5dd4f0f5fd1311345155854a", name: "英雄分类", __v: 0}
		})
		const cats = await Category.aggregate([		//聚合查询，一次执行几次查询的工作量，得到想要的结果（具体看上面新闻列表）
			{ $match: { parent: parent._id } },	//条件：匹配parent._id（看上面）（父_id）
			{
        $lookup: {
          from: 'heroes',								//从heroes集合（具体看models/Hero.js最后一段mongoose.model('Hero'，schema,'heroes')）
          localField: '_id',						//本地字段	Category模型的字段_id
          foreignField: 'categories',		//外地字段	hero集合的字段categories	
          as: 'heroList'								//名字
        }
      }
		])
		const subCats = cats.map(v => v._id)	//遍历出id		
		// console.log(subCats)//6个子id（对应战士，射手等子分类）[ 5dd4f10afd1311345155854b,5dd4f115fd1311345155854c,5dd4f11ffd1311345155854d,5dd4f12bfd1311345155854e,	5dd4f132fd1311345155854f,5dd4f139fd13113451558550 ]
		cats.unshift({				//unshift（一个或多个元素添加到数组的开头）
      name: '热门',
      heroList: await Hero.find().where({		//添加热门中，随机用其他分类的十个英雄
        categories: { $in: subCats }
      }).limit(10).lean()
		})
		// console.log(cats)	看接口数据
		res.send(cats)
	})



	/*
	** 	@routes http://localhost:3000/web/api/articles/:id (动态id)
	**	文章详情接口
	*/
	router.get('/articles/:id',async(req,res)=>{
		const data = await Article.findById(req.params.id).lean()	//通过id找到Article文章列表中的数据，lean()变成json对象
		data.related = await Article.find().where({
			categories: { $in: data.categories }	//$in 匹配，Article模型匹配 categories为Article模型的属性，categories匹配data.categories属性
		}).limit(2)	//限制两条
		res.send(data)
	})



	/*
	** 	@routes http://localhost:3000/web/api/heroes/:id (动态id)
	**	单个英雄接口
	*/
	router.get('/heroes/:id', async (req, res) => {
    const data = await Hero.findById(req.params.id).populate('categories').lean()//找到_id,展开categories(里面有name属性)，变成json对象
    res.send(data)
  })


	/*
	**	http://localhost:3000/web/api 再进行路由跳转操作
	*/
	app.use('/web/api', router)
}



		// cats*10(因为限制了10条数据。现在去改成100)

	// [ { _id: 5dd3bff2fe8d4c4f7e476e5e,
		// 	parent: 5dd3bfd8fe8d4c4f7e476e5c,
		// 	name: '新闻',
		// 	__v: 0 },
		// { _id: 5dd3c027fe8d4c4f7e476e61,
		// 	parent: 5dd3bfd8fe8d4c4f7e476e5c,
		// 	name: '公告',
		// 	__v: 0 },
		// { _id: 5dd3c03bfe8d4c4f7e476e62,
		// 	parent: 5dd3bfd8fe8d4c4f7e476e5c,
		// 	name: '活动',
		// 	__v: 0 },
		// { _id: 5dd3c049fe8d4c4f7e476e63,
		// 	parent: 5dd3bfd8fe8d4c4f7e476e5c,
		// 	name: '赛事',
		// 	__v: 0 } ]   *  10


		//console.log(newsList)

		// {
		// 	categories: [
		// 		{
		// 			_id: "5dd3c03bfe8d4c4f7e476e62",
		// 			parent: "5dd3bfd8fe8d4c4f7e476e5c",
		// 			name: "活动",
		// 			__v: 0
		// 		},
		// 		{
		// 			_id: "5dd3bff2fe8d4c4f7e476e5e",
		// 			parent: "5dd3bfd8fe8d4c4f7e476e5c",
		// 			name: "新闻",
		// 			__v: 0
		// 		}
		// 	],
		// 	title: "11月19日全服不停机更新公告"
		// }, * 10

		// console.log(cats)	
	// 	[ { name: '热门',
  //   newsList: [ [Object], [Object], [Object], [Object], [Object] ] },
  // { _id: 5dd3bff2fe8d4c4f7e476e5e,
  //   parent: 5dd3bfd8fe8d4c4f7e476e5c,
  //   name: '新闻',
  //   __v: 0,
  //   newsList: [ [Object], [Object], [Object], [Object], [Object] ] },
  // { _id: 5dd3c027fe8d4c4f7e476e61,
  //   parent: 5dd3bfd8fe8d4c4f7e476e5c,
  //   name: '公告',
  //   __v: 0,
  //   newsList: [ [Object], [Object], [Object], [Object], [Object] ] },
  // { _id: 5dd3c03bfe8d4c4f7e476e62,
  //   parent: 5dd3bfd8fe8d4c4f7e476e5c,
  //   name: '活动',
  //   __v: 0,
  //   newsList: [ [Object], [Object], [Object], [Object], [Object] ] },
  // { _id: 5dd3c049fe8d4c4f7e476e63,
  //   parent: 5dd3bfd8fe8d4c4f7e476e5c,
  //   name: '赛事',
  //   __v: 0,
	//   newsList: [ [Object], [Object], [Object], [Object], [Object] ] } ]
	
	
	// console.log(cat.heroes) 

	// [	
	// 	{
	// 		categories: [
	// 		"5dd4f10afd1311345155854b"
	// 		],
	// 		items1: [ ],
	// 		items2: [ ],
	// 		_id: "5dd4f578737e5cc1e9d1bb1c",
	// 		name: "赵云",
	// 		avatar: "https://game.gtimg.cn/images/yxzj/img201606/heroimg/107/107.jpg",
	// 		skills: [ ],
	// 		partners: [ ],
	// 		__v: 0
	// 	},
	// 	{
	// 		categories: [
	// 		"5dd4f10afd1311345155854b"
	// 		],
	// 		items1: [ ],
	// 		items2: [ ],
	// 		_id: "5dd4f578737e5cc1e9d1bb1d",
	// 		name: "墨子",
	// 		avatar: "https://game.gtimg.cn/images/yxzj/img201606/heroimg/108/108.jpg",
	// 		skills: [ ],
	// 		partners: [ ],
	// 		__v: 0
	// 		},
	// ]